package com.timmy.google_play.base;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.timmy.google_play.activity.DetailActivity;
import com.timmy.google_play.bean.ItemBean;
import com.timmy.google_play.holder.ItemHolder;
import com.timmy.google_play.manager.DownLoadManager;
import com.timmy.google_play.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Timmy on 2016/12/14.
 */

public class ItemAdapter extends SuperBaseAdapter<ItemBean> {

    private List<ItemHolder> mItemHolders = new ArrayList<>();

    public List<ItemHolder> getItemHolders() {
        return mItemHolders;
    }

    public ItemAdapter(ListView listView, List<ItemBean> datas) {
        super(listView, datas);
    }

    @NonNull
    @Override
    protected BaseHolder<ItemBean> getSpecialBaseHolder(int position) {
        ItemHolder itemHolder = new ItemHolder();

        mItemHolders.add(itemHolder);

        //添加观察者到观察者集合当中
        DownLoadManager.getInstance().addObserver(itemHolder);

        return itemHolder;
    }

    @Override
    public boolean hasLoadMore() {
        return true;
    }

    /**
     * 条目点击事件
     */
    @Override
    protected void onNormalItemClick(AdapterView<?> adapterView, View view, int positon, long id) {

        ItemBean itemBean = mDatas.get(positon);

        //跳转到详情页面
        Intent intent = new Intent(UIUtils.getContext(), DetailActivity.class);

        //添加标记
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        //传递参数
        intent.putExtra("packagename", itemBean.packageName);

        UIUtils.getContext().startActivity(intent);

    }
}
